package com.mdxx.common;

/**
 * Created by MD-01 on 2017/5/3.
 */
public class ResultFactory {
    /**请求成功,无返回值*/
    public static <T> CommonResult<T> ok(){
        CommonResult result = new CommonResult();
        result.setCode(0);
        result.setData(null);
        result.setErrMsg("");
        result.setSucMsg("成功");
        return result;
    }

    /**请求成功,有返回值T*/
    public static <T> CommonResult<T> ok(T t){
        CommonResult result = new CommonResult();
        result.setCode(0);
        result.setData(t);
        result.setErrMsg("");
        result.setSucMsg("成功");
        return result;
    }

    /**请求失败,业务逻辑错误*/
    public static <T> CommonResult<T> error(String errMsg){
        CommonResult result = new CommonResult();
        result.setCode(1);
        result.setData(null);
        result.setErrMsg(errMsg);
        result.setSucMsg("");
        return result;
    }

    /**请求失败,token错误*/
    public static <T> CommonResult<T> tokenError(){
        CommonResult result = new CommonResult();
        result.setCode(2);
        result.setData(null);
        result.setErrMsg("token已经失效");
        result.setSucMsg("");
        return result;
    }

    /**请求失败,请求超时错误*/
    public static <T> CommonResult<T> timeOutError(){
        CommonResult result = new CommonResult();
        result.setCode(3);
        result.setData(null);
        result.setErrMsg("请求超时");
        result.setSucMsg("");
        return result;
    }


    /**请求失败,验证错误(加密解密)*/
    public static <T> CommonResult<T> authError(String errMsg){
        CommonResult result = new CommonResult();
        result.setCode(4);
        result.setData(null);
        result.setErrMsg("加密解密错误");
        result.setSucMsg("");
        return result;
    }

    /**请求失败,服务器异常*/
    public static <T> CommonResult<T> serverError(String errMsg){
        CommonResult result = new CommonResult();
        result.setCode(5);
        result.setData("");
        result.setErrMsg(errMsg);
        result.setSucMsg("");
        return result;
    }
}
